/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package pe.edu.pucp.sistemasInf.view;

import java.awt.Frame;
import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.swing.ImageIcon;
import javax.swing.JFileChooser;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import pe.edu.pucp.sistemasInf.bean.Cliente;
import pe.edu.pucp.sistemasInf.bean.Factura;
import pe.edu.pucp.sistemasInf.controller.DAOCliente;
import pe.edu.pucp.sistemasInf.controller.DAOFactory;
import pe.edu.pucp.sistemasInf.controller.DBConfig;
import pe.edu.pucp.sistemasInf.controller.Service;

/**
 *
 * @author alulab11
 */
public class MóduloFacturaWindow extends javax.swing.JInternalFrame {
    
    Cliente clientPadre = new Cliente();
    String fileImage;
    
    public MóduloFacturaWindow(Cliente clientePadre) {
        initComponents();
        jTextClientePadre.setText(clientePadre.getRazon_Social());
        clientPadre = clientePadre;
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jRadioButtonMenuItem1 = new javax.swing.JRadioButtonMenuItem();
        jRadioButtonMenuItem2 = new javax.swing.JRadioButtonMenuItem();
        jLabel1 = new javax.swing.JLabel();
        textNumFactura = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        btnSearchFactura = new javax.swing.JButton();
        txtMonto = new javax.swing.JTextField();
        txtMora = new javax.swing.JTextField();
        txtPorcInt = new javax.swing.JTextField();
        labelPhoto = new javax.swing.JPanel();
        lblPhoto = new javax.swing.JLabel();
        btnSubirImagenFactura = new javax.swing.JButton();
        btnAgregarFactura = new javax.swing.JButton();
        jButton4 = new javax.swing.JButton();
        jButton5 = new javax.swing.JButton();
        jButton6 = new javax.swing.JButton();
        jLabel6 = new javax.swing.JLabel();
        txtSaldo = new javax.swing.JTextField();
        jLabel8 = new javax.swing.JLabel();
        txtRUC = new javax.swing.JTextField();
        jDateChooser1 = new com.toedter.calendar.JDateChooser();
        jDateChooser2 = new com.toedter.calendar.JDateChooser();
        jLabel9 = new javax.swing.JLabel();
        jTextClientePadre = new javax.swing.JTextField();

        jRadioButtonMenuItem1.setSelected(true);
        jRadioButtonMenuItem1.setText("jRadioButtonMenuItem1");

        jRadioButtonMenuItem2.setSelected(true);
        jRadioButtonMenuItem2.setText("jRadioButtonMenuItem2");

        setClosable(true);

        jLabel1.setText("Número Factura");

        textNumFactura.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                textNumFacturaActionPerformed(evt);
            }
        });

        jLabel2.setText("Monto");

        jLabel3.setText("Fecha Vencimiento");

        jLabel4.setText("%Intereses");

        jLabel5.setText("Fecha Ingreso");

        jLabel7.setText("Saldo");

        btnSearchFactura.setText("Buscar Factura");
        btnSearchFactura.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSearchFacturaActionPerformed(evt);
            }
        });

        txtMora.setText("0");

        txtPorcInt.setText("0");
        txtPorcInt.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtPorcIntActionPerformed(evt);
            }
        });

        labelPhoto.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));

        javax.swing.GroupLayout labelPhotoLayout = new javax.swing.GroupLayout(labelPhoto);
        labelPhoto.setLayout(labelPhotoLayout);
        labelPhotoLayout.setHorizontalGroup(
            labelPhotoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(lblPhoto, javax.swing.GroupLayout.DEFAULT_SIZE, 330, Short.MAX_VALUE)
        );
        labelPhotoLayout.setVerticalGroup(
            labelPhotoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, labelPhotoLayout.createSequentialGroup()
                .addGap(0, 0, Short.MAX_VALUE)
                .addComponent(lblPhoto, javax.swing.GroupLayout.PREFERRED_SIZE, 386, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        btnSubirImagenFactura.setText("Agregar Imagen Factura");
        btnSubirImagenFactura.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSubirImagenFacturaActionPerformed(evt);
            }
        });

        btnAgregarFactura.setText("Agregar Factura");
        btnAgregarFactura.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAgregarFacturaActionPerformed(evt);
            }
        });

        jButton4.setText("Anular Factura");
        jButton4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton4ActionPerformed(evt);
            }
        });

        jButton5.setText("Modificar Factura");
        jButton5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton5ActionPerformed(evt);
            }
        });

        jButton6.setText("Desdoblar Factura");
        jButton6.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton6ActionPerformed(evt);
            }
        });

        jLabel6.setText("Mora(S/.)");

        jLabel8.setText("RUC Cliente");

        jLabel9.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel9.setText("Modulo de Ingreso de Factura de:");

        jTextClientePadre.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jTextClientePadre.setEnabled(false);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(40, 40, 40)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel9)
                        .addGap(18, 18, 18)
                        .addComponent(jTextClientePadre, javax.swing.GroupLayout.PREFERRED_SIZE, 307, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(0, 0, Short.MAX_VALUE))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel5)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(jDateChooser1, javax.swing.GroupLayout.PREFERRED_SIZE, 203, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                .addGap(0, 0, Short.MAX_VALUE)
                                .addComponent(jDateChooser2, javax.swing.GroupLayout.PREFERRED_SIZE, 203, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel6)
                                    .addComponent(jLabel7)
                                    .addComponent(jLabel4))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(txtSaldo)
                                    .addComponent(txtMora)
                                    .addComponent(txtPorcInt, javax.swing.GroupLayout.PREFERRED_SIZE, 203, javax.swing.GroupLayout.PREFERRED_SIZE)))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(btnAgregarFactura, javax.swing.GroupLayout.PREFERRED_SIZE, 125, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 41, Short.MAX_VALUE)
                                .addComponent(btnSearchFactura, javax.swing.GroupLayout.PREFERRED_SIZE, 127, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(31, 31, 31))
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel2)
                                    .addComponent(jLabel8)
                                    .addComponent(jLabel3)
                                    .addComponent(jLabel1))
                                .addGap(35, 35, 35)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                    .addComponent(txtMonto, javax.swing.GroupLayout.DEFAULT_SIZE, 193, Short.MAX_VALUE)
                                    .addComponent(txtRUC, javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(textNumFactura, javax.swing.GroupLayout.Alignment.LEADING))))
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(46, 46, 46)
                                .addComponent(labelPhoto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addContainerGap(57, Short.MAX_VALUE))
                            .addGroup(layout.createSequentialGroup()
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jButton5)
                                .addGap(18, 18, 18)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(layout.createSequentialGroup()
                                        .addComponent(btnSubirImagenFactura, javax.swing.GroupLayout.PREFERRED_SIZE, 163, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                                    .addGroup(layout.createSequentialGroup()
                                        .addComponent(jButton4, javax.swing.GroupLayout.PREFERRED_SIZE, 129, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 17, Short.MAX_VALUE)
                                        .addComponent(jButton6, javax.swing.GroupLayout.PREFERRED_SIZE, 132, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addContainerGap(20, Short.MAX_VALUE))))))))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(30, 30, 30)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel9, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jTextClientePadre, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(labelPhoto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnSubirImagenFactura, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 26, Short.MAX_VALUE)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(btnAgregarFactura, javax.swing.GroupLayout.PREFERRED_SIZE, 47, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jButton4, javax.swing.GroupLayout.PREFERRED_SIZE, 47, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jButton6, javax.swing.GroupLayout.PREFERRED_SIZE, 45, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(btnSearchFactura, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jButton5, javax.swing.GroupLayout.PREFERRED_SIZE, 45, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(0, 0, Short.MAX_VALUE)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel1)
                            .addComponent(textNumFactura, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(27, 27, 27)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(txtRUC, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel8))
                        .addGap(32, 32, 32)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(txtMonto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel2))
                        .addGap(34, 34, 34)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jDateChooser1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel5, javax.swing.GroupLayout.Alignment.TRAILING))
                        .addGap(32, 32, 32)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jDateChooser2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel3))
                        .addGap(26, 26, 26)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(txtSaldo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel7, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(txtMora, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel6))
                        .addGap(21, 21, 21)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel4)
                            .addComponent(txtPorcInt, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(106, 106, 106)))
                .addGap(33, 33, 33))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void textNumFacturaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_textNumFacturaActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_textNumFacturaActionPerformed

    private void txtPorcIntActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtPorcIntActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txtPorcIntActionPerformed

    private void btnAgregarFacturaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAgregarFacturaActionPerformed
        if(!textNumFactura.getText().matches("[0-9]{3}+[-]+[0-9]{7}")||
            !txtRUC.getText().matches("[0-9]{11}") ||
            !txtMonto.getText().matches("[0-9]{1,8}(\\.[0-9]{1,8})?") ||
            !txtSaldo.getText().matches("[0-9]{1,8}(\\.[0-9]{1,8})?") ||
            !txtMora.getText().matches("[0-9]{1,8}(\\.[0-9]{1,8})?")  ||
            !txtPorcInt.getText().matches("[0-9]{1,8}(\\.[0-9]{1,8})?")){
            
            if(!textNumFactura.getText().matches("[0-9]{3}+[-]+[0-9]{7}")){
                JOptionPane.showMessageDialog(this, "Numero de Factura mal ingresado");
            }
            if(!txtRUC.getText().matches("[0-9]{11}") ){
                JOptionPane.showMessageDialog(this, "RUC mal ingresado");
            }          
            if(!txtMonto.getText().matches("[0-9]{1,8}(\\.[0-9]{1,8})?")){
                  JOptionPane.showMessageDialog(this, "Monto mal ingresado");
            }
            if(!txtSaldo.getText().matches("[0-9]{1,8}(\\.[0-9]{1,8})?")){
                  JOptionPane.showMessageDialog(this, "Saldo mal ingresado");
            }
            if(!txtMora.getText().matches("[0-9]{1,8}(\\.[0-9]{1,8})?")){
                  JOptionPane.showMessageDialog(this, "Mora mal ingresada");
            }
            if(!txtPorcInt.getText().matches("[0-9]{1,8}(\\.[0-9]{1,8})?")){
                  JOptionPane.showMessageDialog(this, "interes mal ingresado");
            }
            
        }else{
        Factura factura=new Factura();
        Cliente clienteHijo = new Cliente();
        factura.setNumero_Factura(textNumFactura.getText());
        factura.setMonto_Total(Double.parseDouble(txtMonto.getText()));
        factura.setSaldo(Double.parseDouble(txtSaldo.getText()));
        SimpleDateFormat df = new SimpleDateFormat();
        df.applyPattern("dd/mm/yyyy");

        String fechaemision=df.format(jDateChooser1.getDate());
        factura.setFecha_emision(jDateChooser1.getDate());
        String fechavencimiento=df.format(jDateChooser2.getDate());
        factura.setFecha_vencimiento(jDateChooser2.getDate());       
        factura.setEstado("H");
        factura.setImpuesto_mora(Double.parseDouble(txtMora.getText()));
        factura.setMonto_intereses(0.0);
        if (fileImage!=null)
             factura.setPhoto(new File(fileImage));
        DAOFactory daoFactory = DAOFactory.getDAOFactory(DBConfig.dbType);
        DAOCliente daoCliente = daoFactory.getDAOCliente();
        //verificar que el cliente exista
        clienteHijo = new Service().queryClienteByRUC(txtRUC.getText());
        //colocar en agregar factura solo si el cliente existe
        new Service().addFactura(factura, clientPadre.getCod_Cliente(),clienteHijo.getCod_Cliente());
        }
    }//GEN-LAST:event_btnAgregarFacturaActionPerformed

    private void btnSubirImagenFacturaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSubirImagenFacturaActionPerformed
     
        JFileChooser fileChooser = new JFileChooser();
        int res = fileChooser.showOpenDialog(null);
        if (res == JFileChooser.APPROVE_OPTION){
            File file = fileChooser.getSelectedFile();
            JOptionPane.showMessageDialog(null, file.getAbsolutePath());
            lblPhoto.setIcon(new ImageIcon(file.getAbsolutePath()));            
            fileImage=file.getAbsolutePath();
        }
    }//GEN-LAST:event_btnSubirImagenFacturaActionPerformed

    private void btnSearchFacturaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSearchFacturaActionPerformed
        // TODO add your handling code here:
        FiltrarFacturas ff=new FiltrarFacturas(new Frame(),true);
        ff.setVisible(true);
        if(ff.seleccionado==1){
            Factura fact=ff.getFacturaselected();
            ff.dispose();
            Cliente c=new Service().queryClienteByCod(fact.getCod_Cliente());
            textNumFactura.setText(fact.getNumero_Factura());
            txtRUC.setText(c.getRUC());
            txtMonto.setText(String.valueOf(fact.getMonto_Total()));
            jDateChooser1.setDate(fact.getFecha_emision());
            jDateChooser2.setDate(fact.getFecha_vencimiento());
            txtSaldo.setText(fact.getSaldo().toString());
            txtMora.setText(fact.getImpuesto_mora().toString());
            txtPorcInt.setText(fact.getMonto_intereses().toString());

            
        }
    }//GEN-LAST:event_btnSearchFacturaActionPerformed

    private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton6ActionPerformed
        // TODO add your handling code here:
        DesdoblarFacturaWindow desfactura=new DesdoblarFacturaWindow(new Frame(),true,textNumFactura.getText());
        desfactura.setVisible(true);
    }//GEN-LAST:event_jButton6ActionPerformed

    private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton5ActionPerformed
        // TODO add your handling code here:
        Factura factura=new Factura();
        Cliente clienteHijo = new Cliente();
        factura.setNumero_Factura(textNumFactura.getText());
        factura.setMonto_Total(Double.parseDouble(txtMonto.getText()));
        factura.setSaldo(Double.parseDouble(txtSaldo.getText()));
        SimpleDateFormat df = new SimpleDateFormat();
        df.applyPattern("dd/mm/yyyy");

        String fechaemision=df.format(jDateChooser1.getDate());
        factura.setFecha_emision(jDateChooser1.getDate());
        String fechavencimiento=df.format(jDateChooser2.getDate());
        factura.setFecha_vencimiento(jDateChooser2.getDate());       
        factura.setEstado("H");
        factura.setImpuesto_mora(Double.parseDouble(txtMora.getText()));
        factura.setMonto_intereses(0.0);
        
        new Service().updateFactura(factura);
        
    }//GEN-LAST:event_jButton5ActionPerformed


    private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed
        // TODO add your handling code here:
        
    }//GEN-LAST:event_jButton4ActionPerformed

    private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton5ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jButton5ActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnAgregarFactura;
    private javax.swing.JButton btnSearchFactura;
    private javax.swing.JButton btnSubirImagenFactura;
    private javax.swing.JButton jButton4;
    private javax.swing.JButton jButton5;
    private javax.swing.JButton jButton6;
    private com.toedter.calendar.JDateChooser jDateChooser1;
    private com.toedter.calendar.JDateChooser jDateChooser2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JRadioButtonMenuItem jRadioButtonMenuItem1;
    private javax.swing.JRadioButtonMenuItem jRadioButtonMenuItem2;
    private javax.swing.JTextField jTextClientePadre;
    private javax.swing.JPanel labelPhoto;
    private javax.swing.JLabel lblPhoto;
    private javax.swing.JTextField textNumFactura;
    private javax.swing.JTextField txtMonto;
    private javax.swing.JTextField txtMora;
    private javax.swing.JTextField txtPorcInt;
    private javax.swing.JTextField txtRUC;
    private javax.swing.JTextField txtSaldo;
    // End of variables declaration//GEN-END:variables
}
